<template>
  <div class="app-container">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" style="margin-left: 70px;" >
<!--        <span style="font-size: 18px;">安全隐患监督台账详情</span>-->
<!--        <el-divider></el-divider>-->
        <el-row>
          <el-col :span="8" class="elcol">
            <el-form-item label="检查日期:" prop="checkDate" >{{ form.checkDate | dateString('YYYY-MM-DD') }}
            </el-form-item>
          </el-col>
          <el-col :span="8" class="elcol">
            <el-form-item label="检查类型:" prop="checkType" >{{typeFormat(form.checkType)}}
            </el-form-item>
          </el-col>
          <el-col :span="8" class="elcol">
            <el-form-item label="检查人:" prop="personInCharge" >{{form.personInCharge}}
            </el-form-item>
          </el-col>
        </el-row>
<!--        日常检查-->
        <div style="overflow-y:auto;height:680px;">
          <div v-for="(item,index) in form.dailies" :key="item.id">
            <el-form-item v-model="item.checkContent"  style="margin-left: -70px;margin-bottom: 0px"><span style="font-size: 16px;font-weight: 700">{{index+1}}、{{item.checkContent}}</span></el-form-item>
            <el-row style="margin-left: 88px;">
              <el-col :span="8" class="elcol">
                <el-form-item  label="是否存在问题：" style="margin-bottom: 0px;">{{isProblemFormat(item.isProblems)}}
<!--                  <el-radio-group  v-model="item.isProblems">-->
<!--                    <el-radio :disabled="true"-->
<!--                              v-for="dict in dictList"-->
<!--                              :key="dict.dictValue"-->
<!--                              :label="dict.dictValue"-->
<!--                    >{{dict.dictLabel}}</el-radio>-->
<!--                  </el-radio-group>-->
                </el-form-item>
              </el-col>
              <el-col :span="16">
                <div>
                  <el-row>
                    <el-col :span="8" style="width: 35.3%">
                      <el-form-item label="整改情况:" v-show="item.isProblems == 1" style="margin-bottom: 0px">{{rectificationTypeFormat(item.rectificationType)}}
<!--                        <el-radio-group v-model="item.rectificationType">-->
<!--                          <el-radio-->
<!--                            :disabled="true"-->
<!--                            v-for="dict in rectificationOptions"-->
<!--                            :key="dict.dictValue"-->
<!--                            :label="dict.dictValue"-->
<!--                          >{{dict.dictLabel}}</el-radio>-->
<!--                        </el-radio-group>-->
                      </el-form-item>
                    </el-col>
                    <el-col :span="8" class="elcol">
                      <el-form-item prop="termDate" label="期限日期:" style="width: 200px;margin-bottom: 0px" v-show="item.rectificationType==1 && item.isProblems ==1">{{ item.termDate | dateString('YYYY-MM-DD') }}
<!--                        <el-date-picker clearable size="small" style="width: 200px;margin-left: -328px;margin-bottom: 0px" :readonly="true"-->
<!--                                        v-model="item.termDate"-->
<!--                                        type="date"-->
<!--                                        value-format="yyyy-MM-dd"-->
<!--                                        placeholder="选择期限日期">-->
<!--                        </el-date-picker>-->
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="16">
                <el-form-item label="描述:" style="margin-left: 24px;margin-bottom: 0px;"></el-form-item>
                <el-form-item style="margin-left: -20px;">
<!--                  <el-input v-model="item.description" type="textarea" :rows="10" style="width: 90%;"></el-input>-->
                  <textarea v-model="item.description" class="add_textarea" style="width: 90%;height: 230px"></textarea>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-button v-if="item.isProblems == '1' && item.isRectification != '1' && item.rectificationType == 1" disabled style="color: black"
                ><span style="font-size: 16px;font-weight: 700">未整改</span></el-button>
                <el-button v-if="item.isProblems != '0' &&(item.isRectification == '1' || item.rectificationType == 0)" disabled style="color: black">
                  <span style="font-size: 16px;font-weight: 700">已整改</span>
                </el-button>
              </el-col>
            </el-row>

            <el-form-item style="margin-left: -20px;">
              <el-upload
                :disabled="true"
                :action="upload.url"
                :class="{disabled:true}"
                :file-list="item.imgList"
                list-type="picture-card"
                :on-preview="handlePictureCardPreview">
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
            <div v-if="item.isRectification ==1 && item.rectificationType ==1">
              <el-form-item label="整改日期:" style="margin-bottom: 0px;margin-left: 50px;" >{{ item.reinspectionDate | dateString('YYYY-MM-DD') }}
              </el-form-item>
              <el-form-item label="整改描述:" style="margin-left: 50px;margin-bottom: 0px;"></el-form-item>
              <el-form-item style="margin-left: -22px;">
                <textarea v-model="item.rectificationOpinion" class="add_textarea" style="width: 58%;height: 230px"></textarea>
              </el-form-item>

              <el-form-item style="margin-left: -22px;">
                <el-upload
                  :disabled="true"
                  :action="upload.url"
                  :class="{disabled:true}"
                  :file-list="item.checkImgsList"
                  list-type="picture-card"
                  :on-preview="handlePictureCardPreview">
                  <i class="el-icon-plus"></i>
                </el-upload>
              </el-form-item>
            </div>
          </div>
        </div>
      </el-form>
      <div slot="footer" style="float: right;margin-right: 20%" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
import {getInspection, updateInspection, updateDaily } from "@/api/ledger/inspection";
import { getToken } from "@/utils/auth";
export default {
  name: "Inspection",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      value: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,

      // 安全管理监督检查台账表格数据
      inspection: {},
      inspectionContentList: [],
      typeOptions:[],
      typeOptionList:[],
      rectificationOptions:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      is_show: false,
      termDate_show: false,
      rectification_show: false,
      openView: false,
      openRectification: false,
      station_btn: false,
      tableHeight: window.innerHeight - 275,
      //日期范围
      dateRange: [],
      srcList:[],
      checkSrcList:[],
      dictList:[],
      // 表单参数
      form2:{},
      form: {
        id: undefined,
        stationId: undefined,
        checkDate: undefined,
        checkCompany: undefined,
        personInCharge: undefined,
        checkDeptWorker: undefined,
        existingProblems: undefined,
        rectificationOpinion: undefined,
        rectificationResults: undefined,
        reinspectionPerson: undefined,
        reinspectionPersonDate: undefined,
        delFlag: undefined,
        createTime: undefined,
        createId: undefined,
        updateTime: undefined,
        updateId: undefined,
        remark: undefined,
        checkType: undefined,
        checkObject: undefined,
        checkContent: undefined,
        isProblems: undefined,
        isRectification: undefined,
        dailies:[],
        problem: [],
        rectification: [],
        termDate: [],
        content: [],
        description: [],
        imgList2: [],
        imgList: [],
        imgs2:[],
        imgs:[],
        checkImgsList: [],
        checkImgs:[],
      },
      upload: {
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/upload",
        //  文件个数
        limit: 5
      },
      // 表单校验
      rules: {
        reinspectionDate: [
          { required: true, message: "整改日期不能为空", trigger: "blur" }
        ],
        rectificationOpinion: [
          { required: true, message: "整改描述不能为空", trigger: "blur" }
        ],
      },
      id:undefined,
      dialogImageUrl: '',
      dialogVisible: false,};
  },
  watch: {
    $route: function(to,from){
      //do something
      this.getInspection();
    },
  },
  created() {
    this.reset();
    const id = this.$route.params && this.$route.params.id;
    this.id = id;
    this.getInspection()

    this.dictList = [{"dictValue":"1","dictLabel":"是"},{"dictValue":"0","dictLabel":"否"}]
    this.rectificationOptions = [{"dictValue":"0","dictLabel":"现场整改"},{"dictValue":"1","dictLabel":"期限整改"}]
  },
  methods: {
    getInspection(){
      getInspection(this.id).then(response =>{
        this.form = response.data;
        console.log(this.form.dailies)
        this.form.dailies.forEach(response=>{
          const imgs = [];
          const checkImgs = [];
          response.imgList.map(function (item) {
            imgs.push(item.url)
          })
          response.checkImgsList.map(function (item) {
            checkImgs.push(item.url)
          })
          response.imgs = imgs;
          response.checkImgs = checkImgs;
        })
      })
    },
    // 取消按钮
    cancel() {
      console.log("cancel");
      // this.$router.push({path: "/inspection/index", meta: { title: "aaa" }});
      this.$store.dispatch("tagsView/delView", this.$route);
      this.toLastView();
    },
    toLastView() {
      const latestView = this.$store.state.tagsView.visitedViews.slice(-1)[0];
      console.log(latestView.path);
      if (latestView) {
        this.$router.push(latestView);
      } else {
        // now the default is to redirect to the home page if there is no tags-view,
        // you can adjust it according to your needs.
        this.$router.push("/");
      }
    },
    // 表单重置
    reset() {
      this.form2 = {
        id: undefined,
        inspectionId: undefined,
        isRectification:undefined,
        reinspectionDate:undefined,
        rectificationOpinion:undefined,
        checkImgsList: [],
        checkImgs:[],
      };
      this.resetForm("form2");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    // 检查类型
    typeFormat(val) {
      if (val === '0')
        return "日常检查"
      if (val === '1')
        return "专项检查"
    },
    isProblemFormat(value) {
      return this.selectDictLabel(this.dictList, value);
    },
    rectificationTypeFormat(value) {
      return this.selectDictLabel(this.rectificationOptions, value);
    },
  }
};
</script>
<style>
  .disabled .el-upload--picture-card {
    display: none;
  }
</style>
<style>
  .el-upload--picture-card{
    width: 120px;
    height: 120px;
  }
  .el-upload-list--picture-card .el-upload-list__item {
    width: 120px;
    height: 120px;
  }
</style>
<style scoped>
  .img ul{
    padding: 0;
  }
  .img ul li{
    float:left;
    width:20%;
    list-style:none;
    width: 146px;
    margin-right: 2%;
  }
  .elcol{
    width: 24.333333%;
  }
  .add_textarea{
    display: block;
    resize: vertical;
    padding: 5px 15px;
    line-height: 1.5;
    box-sizing: border-box;
    width: 100%;
    font-size: inherit;
    color: #606266;
    background-color: #fff;
    background-image: none;
    border: 1px solid #DCDFE6;
    border-radius: 4px;
    outline-color:#b3e5fc;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  }
  @import '../../../assets/styles/ledger_style.scss';
</style>

